<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/2005/Atom"
                xmlns:a="http://www.w3.org/2005/Atom"
                xmlns:app="http://purl.org/atom/app#"
                xmlns:bc="http://brightcontent.net/ns/"
                xmlns:bce="http://brightcontent.net/ns/extensions"
                xmlns:xh="http://www.w3.org/1999/xhtml"
                xmlns:f="http://xmlns.4suite.org/ext"
                xmlns:func="http://exslt.org/functions"
                xmlns:regexp="http://exslt.org/regular-expressions"
                xmlns:date="http://exslt.org/date-and-times"
                extension-element-prefixes="f func date"
                exclude-result-prefixes="xh a app f bce bc regexp #default">

 <xsl:param name="bc:old_id" />
 <xsl:param name="bc:old_selflink" />
 <xsl:param name="bc:old_permalink" />
 <xsl:param name="bc:old_editlink" />
 <xsl:param name="bc:app_edited" select="f:strftime('%Y-%m-%dT%H:%M:%SZ')" />

 <xsl:template match="/">
  <xsl:apply-templates />
 </xsl:template>

 <!-- create our new entry -->
 <xsl:template match="a:entry">
  <xsl:copy>
   <a:id><xsl:value-of select="$bc:old_id" /></a:id>
   <!-- add author info -->
   <xsl:if test="count(./a:author) = 0">
    <xsl:apply-templates select="../a:author" />
   </xsl:if>
   <xsl:copy-of select="@*" />
   <xsl:apply-templates />
   <app:edited><xsl:value-of select="$bc:app_edited" /></app:edited>
   <a:link title="permalink" rel="alternate" href="{$bc:old_permalink}" />
   <a:link title="atom" rel="self" href="{$bc:old_selflink}" />
   <a:link title="edit" rel="edit" href="{$bc:old_editlink}" />
  </xsl:copy>
 </xsl:template>

 <!-- element we don't want to copy -->
 <xsl:template match="a:link[@rel = 'self'] | a:link[@rel = 'alternate'] | a:link[@rel = 'edit'] | a:id | app:edited" />
 <!-- invalid rel types we get rid of... b/c eric blew it and made one up at one point... -->
 <xsl:template match="a:link[@rel != 'alternate'] | a:link[@rel != 'enclosure'] | a:link[@rel != 'related'] | a:link[@rel != 'self'] | a:link[@rel != 'via']" />

 <!-- elements to copy blindly -->
 <xsl:template match="node()">
  <xsl:copy>
   <xsl:copy-of select="@*" />
   <xsl:apply-templates />
  </xsl:copy>
 </xsl:template>

</xsl:stylesheet>